(function(){
var display = function(o, game_type)
{
	for (var _game_type in o.boxes)
	{
		o.boxes[_game_type].style.display = 'none';
		o.tags[_game_type].className = 'unTagClick';
	}
	if (o.boxes[game_type])
	{
		o.boxes[game_type].style.display = 'block';
		o.tags[game_type].className = 'onTagClick';
		o.onchange(game_type);
		o.game_type = game_type;
		return game_type;
	}
}
TabCtrl = function(tab_id, now_type)
{
	if (!(this instanceof TabCtrl))
	{
		return new TabCtrl(tab_id, now_type);
	}
	var me = this;
	var tab = document.getElementById(tab_id);
	tab.style.display = '';
	var lis = tab.childNodes;
    var first_type = null;
    var key_exists = false;
	for (var i=0,L=lis.length; i<L; i++)
	{
		var node = lis[i];
		if (1==node.nodeType)
		{
			var game_type = node.getAttribute('game_type');
                if (game_type == now_type) {key_exists = true;}
                if ( ! first_type) {first_type = game_type;}
			if (boxes_node = document.getElementById(game_type))
			{
				this.tags[game_type] = node;
				this.boxes[game_type] = boxes_node;
				node.className = 'unTagClick';
				node.onclick = function(e)
				{
					var _gtype = this.getAttribute('game_type');
					display(me, _gtype);
				}
			}
		}
	}
	
	display(me, key_exists?now_type:first_type);
}
TabCtrl.prototype = {
	game_type	: null,
	onchange	: function(game_type){},
	tags		: {},
	boxes		: {},
	show		: function(game_type)
	{
		display(this, game_type);
	}
};
})();